import { Key, Suspense } from 'react';
import { Route, Navigate, Routes } from "react-router-dom";
import { Spin } from 'antd';
import routes from './routeData';

export const routeData = routes;

export default () => {
  return (
    <Suspense fallback={<Spin size="large"><div></div></Spin>}>
      <Routes>
        {
          routeData.map((route: any, i: Key | null | undefined) => {
            return (
              route.redirect ?
                <Route
                  key={i}
                  path={route.path}
                  element={<Navigate to={route.redirect} replace />}
                />
                :
                <Route
                  key={i}
                  path={route.path}
                  element={<route.component />}
                />
            );
          })
        }
      </Routes>
    </Suspense>
  )
}